package hongcaosp.app.android.contact;

import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;
import android.webkit.WebView;
import android.widget.TextView;

import hongcaosp.app.android.BuildConfig;
import hongcaosp.app.android.R;
import xlj.lib.android.base.component.BaseActivity;
import xlj.lib.android.base.toastcompat.ToastManager;
import xlj.lib.android.base.utils.ScreenUtils;
import xlj.lib.android.base.utils.StatusBarUtil;
import xlj.lib.android.base.view.MyWebView;

/**
 * 聊天页面
 */
public class IMActivity extends BaseActivity {
    private MyWebView webView;
    private TextView titleTV;


    @Override
    protected void initView() {
        StatusBarUtil.setStatusBarDarkTheme(this,false);
        webView = findViewById(R.id.webview);
        titleTV = findViewById(R.id.title);

        findViewById(R.id.back_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        AndroidBug5497Workaround.assistActivity(this);

        if (ScreenUtils.checkDeviceHasNavigationBar(this)) {
            int flag = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide
                    //  | View.SYSTEM_UI_FLAG_FULLSCREEN // 不隐藏状态栏，因为隐藏了比如时间电量等信息也会隐藏
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
            View decorView = getWindow().getDecorView();
            // 获取属性
            decorView.setSystemUiVisibility(flag);
        }
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_im;
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void initData(Intent intent) {
        String userName = intent.getStringExtra("userName");
        titleTV.setText(userName);
        String userId = intent.getStringExtra("userId");
        String toUserId = intent.getStringExtra("toUserId");
        String url = BuildConfig.HOST + "/im/index?" + "user_id=" + userId + "&to_user_id=" + toUserId;
        webView.loadUrl(url);
    }

    public static void toIM(Context context,String userName,String userId,String toUserId) {
        if (userId == null || userId.equals(toUserId)) {
            ToastManager.getInstance().showToast("无法发私信给自己");
            return;
        }
        if (context != null) {
            Intent intent = new Intent(context,IMActivity.class);
            intent.putExtra("userName",userName);
            intent.putExtra("userId",userId);
            intent.putExtra("toUserId",toUserId);
            context.startActivity(intent);
        }
    }
}
